package com.beiing.tianshuai.tianshuai.dongtai.presenter;

import com.beiing.tianshuai.tianshuai.dongtai.CallBack;
import com.beiing.tianshuai.tianshuai.dongtai.model.CommentReplyModel;
import com.beiing.tianshuai.tianshuai.dongtai.model.CommentReplyModelImpl;
import com.beiing.tianshuai.tianshuai.dongtai.view.CommentReplyViewImpl;
import com.beiing.tianshuai.tianshuai.entity.DynamicAddReplyBean;
import com.beiing.tianshuai.tianshuai.entity.DynamicDeleteBean;
import com.beiing.tianshuai.tianshuai.entity.DynamicDetailBean;

/**
 * Created by magikliu on 2017/8/22.
 */

public class CommentReplyPresenter implements CommentReplyPresenterImpl {

    private CommentReplyViewImpl mView;
    private CommentReplyModelImpl mModel;

    public CommentReplyPresenter(CommentReplyViewImpl mView) {
        this.mView = mView;
        mModel = new CommentReplyModel();
    }

    @Override
    public void addReply(final String did, String cid, final String form_uid, String to_uid, String content, String registration_id) {
        mModel.addReply(did, cid, form_uid, to_uid, content, registration_id, new CallBack<DynamicAddReplyBean>() {

            @Override
            public void result(DynamicAddReplyBean bean) {
                getReply(form_uid, did);
            }

            @Override
            public void error(Throwable e) {

            }
        });
    }

    @Override
    public void getReply(String uid, String id) {
        mModel.getReply(uid, id, new CallBack<DynamicDetailBean>() {
            @Override
            public void result(DynamicDetailBean bean) {
                mView.showReply(bean);
            }

            @Override
            public void error(Throwable e) {

            }
        });
    }

    @Override
    public void deleteReply(String uid, String id, final int position) {
        mModel.deleteReply(uid, id, new CallBack<DynamicDeleteBean>() {

            @Override
            public void result(DynamicDeleteBean bean) {
                mView.removeReply(position);
            }

            @Override
            public void error(Throwable e) {

            }
        });
    }
}
